﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BOM.dao
{
    class CodeRuleNew
    {
        //插入数据
        public static bool InsertCodeRule()
        { 
            CodeRule rule = new CodeRule();
            string cmdText = "insert into coderule (fname) values ('" + rule.Fname + "')";
            int i = DbService.executeSQL(cmdText);
            if (i == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //得到刚才插入的主键的值
        public static DataTable GetFid()
        {
            string cmdText = "select top 1 fid from coderule order by fid desc";
            DataTable table = DbService.getSQLTable(cmdText, "coderule");
            if (table.Rows.Count == 1)
            {
                return table;
            }
            else
            {
                return null;
            }
        }
        //查询表中数据
        public static bool SelectCodeRule()
        {
            string cmdText = "select * from coderule";
            DataTable table = DbService.getSQLTable(cmdText, "coderule");
            if (table.Rows.Count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //根据fid修改表中数据
        public static bool UpdateCodeRule(int fid)
        { 
            CodeRule coderule = new CodeRule();
            string cmdText = "update Coderule set fname = '" + coderule.Fname + "', Findex = " + coderule.Findex + " where fid = " + fid + "";
            int i = DbService.executeSQL(cmdText);
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //根据fid查询数据
        public static DataTable SelectFidCodeRule(int fid)
        {
            string cmdText = "select * from coderule where fid = " + fid + "";
            DataTable table = DbService.getSQLTable(cmdText, "coderule");
            return table;
        }
        //根据fid删除数据
        public static void DeleteCodeRule(int fid)
        {
            string cmdText = "delete from CodeRule where fid = " + fid + "";
            int i = DbService.executeSQL(cmdText);
        }
    }
}
